package com.xzc.java8.D_Collector;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * 对于 IDENTITY_FINISH这种集合操作，可以直接给collect接口传入方法引用，来实现一个新的累积器
 */
public class IdentityFinishTest {

    @Test
    public void test() {
        List<Apple> list0 = new ArrayList<>();
        Apple a0 = new Apple("a0", "red", 150, 2011);
        Apple a1 = new Apple("a1", "blue", 10, 2012);
        Apple a2 = new Apple("a2", "red", 110, 2011);
        Apple a3 = new Apple("a3", "yellow", 140, 2013);
        list0.add(a0);
        list0.add(a1);
        list0.add(a2);
        list0.add(a3);

        List<Apple> list1 = list0.stream().collect(ArrayList::new, List::add, List::addAll);
        System.out.println(list1);
    }
}
